package com.activenetwork.util.datepicker;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;

import com.activenetwork.smlite.page.generic.PageObject;
import com.activenetwork.util.PageLoader;
import com.activenetwork.util.WaitUtil;

public class CalendarDateDiv implements PageObject {
	private WaitUtil waitUtil = new WaitUtil(500);
	
	@FindBy(how = How.CSS, using = ".datepicker.dropdown-menu[style*='display: block;'] div.datepicker-days")
	private WebElement div;
	
	
	public CalendarMonthDiv switchMonth(){
		div.findElement(By.xpath(".//th[@class='switch']")).click();
		waitUtil.waiting();
		return PageLoader.load(CalendarMonthDiv.class);
	}
	
	public void pick(int date){
		List<WebElement> dates = div.findElements(By.xpath(".//td[text()='" + date + "']"));
		for(WebElement d : dates){
			String cls = d.getAttribute("class").trim();
			if(StringUtils.containsIgnoreCase(cls, "old")){
				continue;
			}else if(StringUtils.equalsIgnoreCase(cls, "day")||StringUtils.equalsIgnoreCase(cls, "day active")){
				d.click();
				break;
			}
		}
	}

}
